package com.tudouji.project.flow.controller;

import com.flow.service.pojo.flow.FlowTemp;
import com.flow.service.process.service.IFlowTempService;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.framework.web.page.TableDataInfo;
import com.tudouji.project.flow.domain.Flowtemp;
import com.tudouji.project.flow.service.IFlowtempService;
import com.tudouji.project.permission.service.IPermissiondefService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 流程Controller
 *
 * @author tudouji
 * @date 2021-05-20
 */
@RestController
@RequestMapping("/flow/flowtemp")
public class FlowtempController extends BaseController
{
    @Autowired
    private IFlowtempService flowtempService;
    @Autowired
    private IFlowTempService tempService;
    @Autowired
    private IPermissiondefService permissiondefService;
    /**
     * 查询流程列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Flowtemp flowtemp)
    {
        startPage();
        List<Flowtemp> list = flowtempService.selectFlowtempList(flowtemp);
        return getDataTable(list);
    }
    /**
     * 查询流程列表
     */
    @GetMapping("/newList")
    public AjaxResult get()
    {
        List<FlowTemp> list = tempService.selectFlowtempList(new FlowTemp());
        return AjaxResult.success(list);
    }

    /**
     * 导出流程列表
     */
    @PreAuthorize("@ss.hasPermi('flow:flowtemp:export')")
    @Log(title = "流程", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Flowtemp flowtemp)
    {
        List<Flowtemp> list = flowtempService.selectFlowtempList(flowtemp);
        ExcelUtil<Flowtemp> util = new ExcelUtil<Flowtemp>(Flowtemp.class);
        return util.exportExcel(list, "flowtemp");
    }

    /**
     * 获取流程详细信息
     */
    @PreAuthorize("@ss.hasPermi('flow:flowtemp:query')")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(flowtempService.selectFlowtempById(guid));
    }





    /**
     * 新增流程
     */
    @PreAuthorize("@ss.hasPermi('flow:flowtemp:add')")
    @Log(title = "流程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Flowtemp flowtemp)
    {
        return toAjax(flowtempService.insertFlowtemp(flowtemp));
    }

    /**
     * 修改流程
     */
    @PreAuthorize("@ss.hasPermi('flow:flowtemp:edit')")
    @Log(title = "流程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Flowtemp flowtemp)
    {
        return toAjax(flowtempService.updateFlowtemp(flowtemp));
    }

    /**
     * 删除流程
     */
    @PreAuthorize("@ss.hasPermi('flow:flowtemp:remove')")
    @Log(title = "流程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(flowtempService.deleteFlowtempByIds(guids));
    }


    @GetMapping("/getFlowtemp")
    public AjaxResult getFlowtemp(FlowTemp flowtemp)
    {
        List<FlowTemp> list = tempService.selectFlowtempList(flowtemp);
        return AjaxResult.success(list);
    }

    @GetMapping("/getDataPermiss")
    public AjaxResult getFlowtemp(Long id)
    {
        FlowTemp flowtemp = tempService.selectFlowtempById(id);
        return AjaxResult.success(flowtemp);
    }


    @GetMapping("/showPrice")
    public AjaxResult showPrice(Long id)
    {
        return permissiondefService.showPrice(id);
    }
}
